package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertDataHandleDto;
import com.zzyl.service.AlertDataService;
import com.zzyl.vo.AlertDataVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-data")
@ApiModel(description = "报警数据")
public class AlertDataController extends BaseController{

    @Autowired
    private AlertDataService alertDataService;


    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询报警数据")
    public ResponseResult<PageResponse<AlertDataVo>> getAlertDataPage(
            @ApiParam(value = "页码", required = true) @RequestParam("pageNum")Integer pageNum,
            @ApiParam(value = "每页大小", required = true) @RequestParam("pageSize")Integer pageSize,
            @ApiParam(value = "设备名称,精确搜索") @RequestParam(value = "deviceName", required = false)String deviceName,
            @ApiParam(value = "结束报警时间") @RequestParam(value = "endTime", required = false)Long endTime,
            @ApiParam(value = "报警数据id") @RequestParam(value = "id", required = false)Long id,
            @ApiParam(value = "开始报警时间") @RequestParam(value = "startTime", required = false)Long startTime,
            @ApiParam(value = "状态，0：待处理，1：已处理") @RequestParam(value = "status", required = false)Integer status){
        PageResponse<AlertDataVo> pageResponse = alertDataService.getAlertDataPage(pageNum, pageSize, deviceName, endTime, id, startTime, status);

        return ResponseResult.success(pageResponse);
    }


    @PutMapping("/handleAlertData/{id}")
    @ApiOperation(value = "处理报警数据")
    public ResponseResult handleAlertData(@RequestBody AlertDataHandleDto alertDataHandleDto, @PathVariable("id") Long id){
        alertDataService.handleAlertData(alertDataHandleDto,id);
        return success();
    }

}
